package com.gp.testonline.controller;

import com.gp.testonline.eo.RppEOPage;
import com.gp.testonline.model.Rpp;
import com.gp.testonline.service.RppService;
import com.gp.testonline.tool.ResponseMessage;
import com.gp.testonline.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对外提供数据服务接口
 */
@Api(tags = "rpp")
@RestController
public class RppController {
    @Autowired
    private RppService rppService;

    @ApiOperation(value = "角色人员权限信息添加方法")
    @RequestMapping(value = "/insertRpp",method = RequestMethod.GET)
    public ResponseMessage insert(Rpp rpp){
        int IsInsert=0;
        //传入数据的判断
        //(1) rpp不能为空
        if (rpp!=null){
            //(2) 编号不能为0
            if (rpp.getRppid()!=0){
                //(3) 添加数据
                IsInsert=rppService.InsertRpp(rpp);
                if (IsInsert==1){
                    return Result.success("添加成功！");
                }else if (IsInsert==-1){
                    return Result.error("添加失败！");
                }else{
                    return Result.error("保存失败！");
                }
            }
        }
        return Result.error("保存失败！");
    }

    @ApiOperation(value = "角色人员权限信息删除方法")
    @RequestMapping(value = "/deleteRpp",method = RequestMethod.GET)
    public ResponseMessage deleteRpp(int rppid){
        int isDelete=0;
        if (rppid!=0){
            isDelete=rppService.DeleteRpp(rppid);
            if (isDelete>0){
                return Result.success("删除成功！");
            }else{
                return Result.error("删除失败！");
            }
        }else {
            return Result.error("删除的主键不能为0，请重新输入！");
        }
    }

    @ApiOperation(value = "角色人员权限信息查询方法")
    @RequestMapping(value = "/getRpp",produces = "application/json;charest=utf-8",method = RequestMethod.PUT)
    public ResponseMessage getRpp(RppEOPage rppEOPage) {
        Map<String, List> map = new HashMap<>();
        List<RppEOPage> listRppEo = rppService.getRppAll(rppEOPage);
        map.put("list",listRppEo);
        return Result.success("200",map);
    }
}
